home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 5 #3 / IMG 46 Vol 5-3.iso / More Goodies / More For Your Game / Realmz / Character Master Source / Character Master / my AppleEvents.cpp < prev    next >
C/C++ Source or Header  |  1996-07-16  |  3KB  |  125 lines

  1. #include "my AppleEvents.h"
  2. #include "character class.h"
  3. #include "my menus.h"
  4. #include "main.h"
  5. #include "my files.h"
  6.  
  7. pascal    OSErr    HandleOAppAE(AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
  8. {
  9.     // Not much to this one 'cos we don't really do much when we open.
  10.     return noErr;
  11. }
  12.  
  13. pascal    OSErr    HandleQuitAE(AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
  14. {
  15.     // Just act as if the user chose quit from the menu.
  16.     OSErr         error = noErr;
  17.  
  18.     error = DoQuitMChoice();
  19.  
  20.     return error;
  21. }
  22.  
  23. pascal    OSErr    HandleODocAE(AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
  24. {
  25.     OSErr        error = noErr, firstError = noErr;
  26.     short        numErrors = 0;
  27.     AEDesc        theList;
  28.     long        numFiles, fileCount;
  29.     
  30.     // the direct object parameter is the list of aliases to files (one or more)
  31.     error = AEGetParamDesc(theAEvent, keyDirectObject, typeAEList, &theList);
  32.     if (error) return error;
  33.  
  34.     // that should be all, but in case something is screwy...
  35.     error = HasUnusedParameters(theAEvent);
  36.     if (error) return error;
  37.  
  38.     // get number of files in list
  39.     error = AECountItems(&theList, &numFiles);
  40.     if (error) return error;
  41.     
  42.     // Check we know where Realmz is. If we don't we can't open characters
  43.  
  44.     if( !CMData()->KnowWhereRealmzIs() )
  45.         DoLocateRealmz();
  46.     
  47.     if( !CMData()->KnowWhereRealmzIs() )
  48.         return error;
  49.  
  50.     FSSpec        fileToOpen;
  51.     long        actualSize;
  52.     AEKeyword    dummyKeyword;
  53.     DescType    dummyType;
  54.     
  55.     // open each file - keep track of errors
  56.     for (fileCount = 1; fileCount <= numFiles; fileCount++)
  57.     {
  58.         // get the alias for the nth file, convert to an FSSpec
  59.         error = AEGetNthPtr(&theList, fileCount, typeFSS, &dummyKeyword, &dummyType, 
  60.                                 (Ptr) &fileToOpen, sizeof(FSSpec), &actualSize);
  61.         if (error) return error;
  62.         
  63.         if( IsOpenableFile( fileToOpen ) )
  64.         {
  65.             // open the file
  66.             error = DoOpen( fileToOpen );
  67.             
  68.             // count file opening errors
  69.             if (error)
  70.             {
  71.                 ++numErrors;    // keep count
  72.                 if (numErrors == 1)                
  73.                     firstError = error; // save first error
  74.             }
  75.         }    // Otherwise just ignore it. Probably the prefs file
  76.     }
  77.  
  78.     // set proper error message
  79.     if (numErrors) // at least one happend
  80.     {
  81.         if (numErrors > 1) // had more than one
  82.         {
  83.             error = kMultipleOpenError;
  84.         }
  85.         else
  86.         {
  87.             error = firstError;
  88.         }
  89.     }
  90.     
  91.     AEDisposeDesc(&theList); // dispose what we allocated
  92.     return error;
  93. }
  94.  
  95. pascal    OSErr    HandlePDocAE(AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
  96. {
  97.     // This function disnae dae much as a cannae print
  98.     return noErr;
  99. }
  100.  
  101. OSErr    HasUnusedParameters(AppleEvent *theAEvent)
  102. {
  103.     OSErr        error;
  104.     long        actualSize;
  105.     DescType    dummyType;
  106.     AEKeyword    missedKeyword;
  107.         
  108.     // Get the "missed keyword" attribute from the AppleEvent.
  109.     error = AEGetAttributePtr(theAEvent, keyMissedKeywordAttr, typeKeyword, &dummyType,
  110.                                 (Ptr)&missedKeyword, sizeof(missedKeyword), &actualSize);
  111.  
  112.     // If the descriptor isn't found, then we got the required parameters.
  113.     if (error == errAEDescNotFound)
  114.     {
  115.         error = noErr;
  116.     }
  117.     else
  118.     {
  119.         error = errAEEventNotHandled;
  120.     }
  121.  
  122.     return error;
  123. }
  124.  
  125.